const dbConnect = require('../database/dbconfig');

// 1获取技术服务列表
let getServiceList = async () => {
    let sql = `SELECT tec_service.id ,tec_service.name AS 技术服务组名, tec_service.img, tec_service_list.name AS 子服务 FROM tec_service INNER JOIN  tec_service_list ON tec_service.id=tec_service_list.c_id  order by tec_service.id`;
    // let sql = `SELECT c_id, GROUP_CONCAT(id,name) FROM tec_service_list GROUP BY c_id`
    let sqlArr = [];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 2新增技术服务组
let createServiceGroup = async (name, img) => {
    let sql = `INSERT INTO tec_service (name,img) VALUES(?,?)`;
    let sqlArr = [name, img];
    let result = await await dbConnect.SySqlConnect(sql, sqlArr);
    return result;
}

// 3修改技术服务组
let updateServieGroup = async (id, name, img) => {
    let sql = `UPDATE tec_service SET name=?,img=? WHERE id=?`;
    let sqlArr = [name, img, id];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}


// 4创建子服务项
let createSubService = async (parentId, name) => {
    let sql = `INSERT INTO tec_service_list (name, c_id) VALUES(?,?)`;
    let sqlArr = [name, parentId];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;
}

// 5删除子服务项
let deleteSubService = async (parentId, id) => {
    let sql = `DELETE FROM tec_service_list WHERE(c_id=? and id=?)`;
    let sqlArr = [parentId, id];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 6修改子服务项
let updateSubService = async (parentId, id, name) => {
    let sql = `UPDATE tec_service_list SET name=? WHERE(c_id=? and id=?)`;
    let sqlArr = [name, parentId, id];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}
// 7获取技术服务展示页信息
let getShowSubService = async () => {
    let sql = `SELECT * FROM tec_service_show`;
    let sqlArr = [];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 8创建新的子服务项案例内容
let createShowSubService = async (parentId, img, ppt, mv, online) => {
    let sql = `INSERT INTO tec_service_example (cate_id, img, ppt, mv, online) VALUES(?,?,?,?,?)`;
    let sqlArr = [parentId, img, ppt, mv, online];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 9修改子服务项案例内容
let updateShowSubService = async (parentId, id, img, ppt, mv, online) => {
    let sql = `UPDATE tec_service_example SET img=?, ppt=?, mv=?, online=?  WHERE(cate_id=? and id=?)`;
    let sqlArr = [parentId, id, img, ppt, mv, online];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 10删除子服务项案例
let deleteShowSubService = async (parentId, id) => {
    let sql = `DELETE FROM tec_service_example WHERE (cate_id=? and id=?)`;
    let sqlArr = [parentId, id];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;
}

// 11获取子服务项案例详情信息
let getExampleInfo = async () => {
    let sql = `SELECT * FROM description_infor`;
    let sqlArr = [];
    let result = await dbConnect.SySqlConnect(sql, sqlArr);
    return result;

}

// 12获取子服务项案例详情信息
// let getExampleInfo = () => {
//     let sql = `SELECT * FROM description_infor`
//     let sqlArr = []
//     let result = await dbConnect.SySqlConnect(sql, sqlArr)
//     return result

// }

// 13创建子服务项目案例详情信息
let createExampleInfo = async (parentId, img, description_list) => {
    let sql = `INSERT INTO description_infor (cate_id, img, description_list) VALUES(?,?,?)`
    let sqlArr = [parentId, img, description_list]
    let result = await dbConnect.SySqlConnect(sql, sqlArr)
    return result;

}

// 14修改子服务项案例详情信息
let updateExampleInfo = async (parentId, id, img, description_list) => {
    let sql = `UPDATE description_infor SET img=?, description_list=? WHERE(cate_id=? and id=?)`
    let sqlArr = [parentId, id, img, description_list]
    let result = await dbConnect.SySqlConnect(sql, sqlArr)
    return result;

}

// 15删除子服务项案例详情信息
let deleteExampleInfo = async (parentId, id) => {
    let sql = `DELETE FROM description_infor`
    let sqlArr = [parentId, id]
    let result = await dbConnect.SySqlConnect(sql, sqlArr)
    return result;

}


module.exports = {
    getServiceList,
    createServiceGroup,
    updateServieGroup,
    updateSubService,
    createSubService,
    deleteSubService,
    updateSubService,
    getShowSubService,
    updateShowSubService,
    createShowSubService,
    deleteShowSubService,
    getExampleInfo,
    createExampleInfo,
    createExampleInfo,
    updateExampleInfo,
    deleteExampleInfo
}